package com.bo.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bo.bean.UserInformation;
import com.bo.tool.RedisUtil;

@Controller
@RequestMapping("redis")
public class RedisController {
	@Autowired
	private RedisUtil redisUtil;
	@Autowired
	private StringRedisTemplate strRedis;
	@Autowired
	private RedisTemplate<String, Object> redisTemplate;
	@RequestMapping("/test")
	@ResponseBody
	public UserInformation test() {

		redisTemplate.opsForValue().set("key1","value1");
		System.out.println("redisTemplate存redisTemplate取："+redisTemplate.opsForValue().get("key1"));
		System.out.println("redisTemplate存stringRedisTemplate取："+strRedis.opsForValue().get("key1"));

		strRedis.opsForValue().set("key2","value2");
		//		System.out.println("stringRedisTemplate存redisTemplate取："+redisTemplate.opsForValue().get("key2"));
		System.out.println("stringRedisTemplate存stringRedisTemplate取："+strRedis.opsForValue().get("key2"));
		redisUtil.set("key3", "value3");
		System.out.println("redisUtil存redisUtil取："+redisUtil.get("key3"));
		//		System.out.println("进入redis");
		//		redisTemplate.opsForValue().set("bcy", "ceshi");
		//		strRedis.opsForValue().set("bo", "ceshi1");
		UserInformation user=new UserInformation();
		user.setAlim_pwd("134421");
		redisUtil.set("user", user);
		System.out.println("redisUtil存redisUtil取："+redisUtil.get("user"));
		//		redisTemplate.opsForValue().set("bo", user,100,TimeUnit.SECONDS);
				UserInformation user1=(UserInformation) redisUtil.get("user");
		//		redisTemplate.opsForHash().p
		//        strRedis.opsForValue().set("bcy", "ceshi");
		        return user1;
//		return   "ceshi";
	}

}
